/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.BevelBorder;

/**
 *
* @author Avi Cohen
 */

public class PrivateChatPanel extends JPanel implements MouseListener,ActionListener,KeyListener
{
    //***********Initialize Arguments****************//
    JTextArea _textArea;
    JTextArea _messageField;
    EmoticonsPanel _Emoticons;
    JButton _send;
    JButton _attach;
    JButton _history;
    JButton _music;
    JButton _invite;
    Font _font;
    Color _TA_Color;
     Image _image3DP;
    Image _wall;
    String _histoy;


    //**********************************************//
    
    /**
     * constructor for PrivateChatPanel
     */
    public PrivateChatPanel()
    {
        //setting the Layout Manager
        setLayout(null);

        //Set the Image
             _wall = Toolkit.getDefaultToolkit().getImage("Pics/Wall.jpg");
            _image3DP=Toolkit.getDefaultToolkit().getImage("3D Postman No BG.gif");
        //Create Colors
            _TA_Color=new Color(255,255,255);//create TextArea color
            

             //Initialize Font
            _font=new Font("Arial",Font.BOLD,13);

        //Initialize TextArea
                _textArea = new JTextArea();
                _textArea.setFont(_font);
                _textArea.setBackground(_TA_Color);
                _textArea.setEditable(false);
                  JScrollPane text_Scroll=new JScrollPane(_textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                text_Scroll.setBounds(100, 50, 500, 350);
                this.add(text_Scroll);
        //initialize message field
            _messageField=new JTextArea("Enter your message here ...");
            _messageField.setFont(_font);
            _messageField.setToolTipText("Enter Your Message Here ...");
            _messageField.setColumns(50);
            _messageField.addKeyListener(this);
            JScrollPane mess_Scroll=new JScrollPane(_messageField, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            mess_Scroll.setBounds(100, 430, 380, 80);
            _messageField.setBorder(new BevelBorder(BevelBorder.LOWERED));
            this.add(mess_Scroll);
        //initialize EmoticonsPanel(Panel)
            _Emoticons=new EmoticonsPanel();
            _Emoticons.setBounds(480, 430,120,40);
            for(int i=0;i<_Emoticons._size;i++)
                _Emoticons._Buttons[i].addMouseListener(this);
            this.add(_Emoticons);
        //initialize "send" button
            _send=new JButton("SEND");
            _send.setBounds(480, 470, 120, 40);
            _send.addMouseListener(this);
            _send.addActionListener(this);

            this.add(_send);

             //initialize "attach" button
            _attach=new JButton("Attach");
            _attach.setBounds(100, 400, 125, 30);
            _attach.addMouseListener(this);
            _attach.addActionListener(this);

            this.add(_attach);

               //initialize "history" button
            _history=new JButton("History");
            _history.setBounds(225, 400,125 , 30);
            _history.addMouseListener(this);
            _history.addActionListener(this);
            this.add(_history);

               //initialize "music" button
            _music=new JButton("Music");
            _music.setBounds(350, 400, 125, 30);
            _music.addMouseListener(this);
            _music.addActionListener(this);
            this.add(_music);



               //initialize "invite" button
            _invite=new JButton("Invite Friends");
            _invite.setBounds(475, 400, 125, 30);
            _invite.addMouseListener(this);
            _invite.addActionListener(this);
            this.add(_invite);



        
    }
    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        _font=new Font("Guttman",Font.BOLD,30);
        g.setFont(_font);
         //draw the images
         g.drawImage(_wall, 0, 0, null);
         g.drawString(this.getToolTipText(),100, 30);


        //paint the color of the panel and he's components by the colors
            _textArea.setBackground(_TA_Color);
            _messageField.setBackground(_TA_Color);



    }
/**
 * this function changes the "theme" of the panel by changing the BackGroung color and the TextArea color
 * @param BG the new Background color
 * @param TA the new TextArea color
 */
    public void ChangeTheme(Color BG,Color TA)
    {
        _TA_Color=TA;
        repaint();
    }
    public void mouseClicked(MouseEvent e) // handle events on emoticons buttons
    {
        String s=_messageField.getText();
        _messageField.setText(null);

        //EmoticonsPanel events
                if(e.getSource()==_Emoticons._Buttons[0])//happy
                {
                    _messageField.insert(s+":-)",0);
                }
                if(e.getSource()==_Emoticons._Buttons[1])//sad
                {
                    _messageField.insert(s+":-(",0);
                }
                if(e.getSource()==_Emoticons._Buttons[2])//wink
                {
                    _messageField.insert(s+";-)",0);
                }
                if(e.getSource()==_Emoticons._Buttons[3])//angry
                {
                    _messageField.insert(s+">:(",0);
                }
        
    }
    public void actionPerformed(ActionEvent e)
    {
        //"send" pressed
                if(e.getSource()==_send)
                {
                    String s=_messageField.getText();
                    _messageField.setText(null);
                    Calendar cal=Calendar.getInstance();
                    String time="("+cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND)+")";
                    _textArea.insert("You Said "+time+" :\n\t"+s+"\n", _textArea.getSelectionEnd());
                }

    }
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void keyPressed(KeyEvent e) {
    }
    public void keyReleased(KeyEvent e) {
    }
    public void keyTyped(KeyEvent e) {
    }
}

   

